﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Aspose.Words;
using System.IO;
namespace Aspose_word
{
    public partial class frmGiayBaoTrungTuyen : Form
    {
        string code = "";
        string html = "";
        public frmGiayBaoTrungTuyen()
        {
            InitializeComponent();
        }
        MemoryStream Stream = new MemoryStream();
        private void btXuat_Click(object sender, EventArgs e)
        {
            code = "";
            if (html == "")
            {
                DB.LinqToSqlDataContext db = new DB.LinqToSqlDataContext();
                var vB = (from vb in db.tbVanBanHtmls
                          where vb.MaVb == "ma1"
                          select vb.DuLieu).SingleOrDefault();
                html = vB;
            }
            for (int i = 0; i < html.Length; i++)
            {   
                if (html[i] == 'x')
                {
                    switch(html[i+1])
                    {
                        case '0': code += txtNgaySinh.Text; break;
                        case '1': code += txtSbd.Text; break;
                        case '2': code += txtDoiTuong.Text; break;
                        case '3': code += txtKvut.Text; break;
                        case '4': code += txtMon1.Text; break;
                        case '5': code += txtMon2.Text; break;
                        case '6': code += txtMon3.Text; break;
                        case '7': code += (Convert.ToInt32(txtMon1.Text) + Convert.ToInt32(txtMon2.Text) + Convert.ToInt32(txtMon3.Text)).ToString(); break;
                        default: break;
                    }
                    i += 2;
                }
                code += html[i];
            }
            Document doc = new Document();
            DocumentBuilder buider = new DocumentBuilder(doc);
            buider.InsertHtml(code);
            MemoryStream stream = new MemoryStream();
            doc.Save(stream, SaveFormat.Doc);
            doc.Save(@"D:\GiayBaoNhapHoc.Doc");
            txtGiayBao.LoadDocument(stream, new DevExpress.XtraRichEdit.DocumentFormat(10));
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DB.LinqToSqlDataContext db = new DB.LinqToSqlDataContext();
            var vB = (from vb in db.tbVanBanHtmls
                     where vb.MaVb == "ma1"
                     select vb.DuLieu).SingleOrDefault();
            html = vB;
        }
    }
}
